package pers.jason.wppm.security.core.validate.code.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;

import pers.jason.wppm.security.core.validate.code.processor.impl.AbstractValidateCodeTemplate;

/**
 * 返回验证码数据
 * @author Jason
 * @Date 2018-10-31 10:50
 *
 */
@RestController
public class ValidateCodeController {
	
	@Autowired
	private Map<String, AbstractValidateCodeTemplate<?>> processors;

	/**
	 * 
	 * @param request
	 * @param type
	 * @throws Exception 
	 */
	@GetMapping("code/{type}")
	public void getValidateCode(HttpServletRequest request, HttpServletResponse response, @PathVariable("type") String type) throws Exception {
		String name = type + "ValidateCodeProcessor";
		AbstractValidateCodeTemplate<?> processor = processors.get(name);
		processor.responseValidateCode(new ServletWebRequest(request, response));
	}
	
}
